package emulator.shell.GUI.menu;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import com.jhe.hexed.JHexEditor;

import emulator.hardware.memory.MemoryBlockInterface;
import emulator.shell.GUI.windows.ManagedWindow;
import emulator.shell.GUI.windows.WindowManager;

public class WindowMemory implements ActionListener {

	private int window_id;
	private WindowManager window_manager;
	private MemoryBlockInterface memory;
	
	public WindowMemory(WindowManager window_manager, int window_id, MemoryBlockInterface memory)
	{
		this.window_manager = window_manager;
		this.window_id = window_id;
		this.memory = memory;
	}

	@Override
	public void actionPerformed(ActionEvent arg0)
	{
		if (window_manager.isWindowActive(window_id))
			closeWindow();
		else
			openWindow();

	}

	private void openWindow() {
		ManagedWindow window = window_manager.createWindow(window_id, "Memory");
		window.getContentPane().add(new JHexEditor(memory.getData()));
		window.restorePosition();
		window.setVisible(true);
	}

	private void closeWindow() {
		window_manager.closeWindow(window_id);
	}

}
